
<!--这里是动态子组件-->
<template>
    <div class="buy">
        <div class="container">
            <el-table :data="data"  style="width: 100%"   ref="multipleTable">
                <el-table-column prop="id" label="ID" width="80" align="center">
                </el-table-column>
                <el-table-column label="封面图" width="240" align="center">
                    <template slot-scope="scope" >
                        <div><img :src="scope.row.head_img" style="width:240px;height:120px"></div>
                    </template>
                </el-table-column>
                              <el-table-column prop="title" label="标题" width="450" align="center">
                </el-table-column>
                <el-table-column prop="city_name" label="所属分站" width="120" align="center">
                </el-table-column>
                <el-table-column prop="create_time" label="创建时间" width="160" align="center">
                </el-table-column>
                 <el-table-column prop="keywords" label="关键词" width="120" align="center" :formatter="formatRole">
                </el-table-column>
                <el-table-column type="expand" label="查看全部详情" width="150" align="center">
                        <template slot-scope="props">
                            <div class="bs-callout bs-callout-danger">
                           <div>
                                   <h3>全部内容：</h3>
                                   <div class="" v-html="props.row.content"></div>
                                   <h3>浏览数：{{props.row.read_num}}</h3>
                            </div>
                          </div>
                    </template>
                </el-table-column>
                    <el-table-column prop="is_checked_text" label="审核状态" width="90" align="center">
                </el-table-column>
                <el-table-column prop="read_num" v-if="!showhide"  label="浏览数"  align="center">
                </el-table-column>
                <el-table-column label="操作" align="center" v-if="showhide">
                    <template slot-scope="scope" >
                        <!-- <el-button class="edit" size="small" type="text" @click="handleLook(scope.$index, scope.row)">查看</el-button> -->
                        <el-button class="del" size="small" type="text"  @click="handleCheck(scope.$index, scope.row)" v-show="scope.row.is_checked==0">审核</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <!-- 审核操作弹出界面 -->
            <el-dialog title="审核" :visible.sync="isChecked"  center width="450px">
                <el-form style="width:400px; margin:0 auto">
                    <el-form-item label="标题：">
                        {{listData.title}}
                    </el-form-item>
                    <el-form-item label="所属分站：">
                         {{listData.city_name}}
                    </el-form-item>
                     <el-form-item label="创建时间：">
                         {{listData.create_time}}
                    </el-form-item>
                    <el-form-item label="审核状态：">
                        <div>
                            <el-radio v-model="state" label="1" border>审核不通过</el-radio>
                            <el-radio v-model="state" label="2" border>审核通过</el-radio>
                        </div>
                    </el-form-item> 
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="isChecked = false">取 消</el-button>
                    <el-button type="primary" @click="confirmCheck">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>
<script>
import { getpubCheckList, postCheckPublish } from "@/api/check/publish";
export default {
  name: "dynamic",
  props: {
    data: Array
  },
  data() {
    return {
      delVisible: false, //默认dialog 不弹出
      isChecked: false, //审核界面默认隐藏 true显示
      id: "", //当前对象id
      state: "1", //审核状态：0审核中，1审核不通过，2审核通过
      listData: [], //操作对象数据
      type: 9, //类型 ：1印厂,2设备,3招聘,4供应,5求购,6心情,7二手,8活动,9动态
      showhide: true
    };
  },
  //实例创建
  created() {},
  //计算属性
  computed: {},
  //方法
  methods: {
    formatRole: function(row, column) {
      if (row.keywords) {
        return JSON.parse(row.keywords);
      }
    },
    getData() {
      let state = this.$parent.state;
      let activeTab = this.$parent.activeTab;
      let userName = this.$parent.userName;
      let title = this.$parent.title;
      let pageIndex = this.$parent.pageIndex;
      let pageSize = this.$parent.pageSize;
      getpubCheckList(
        state,
        activeTab,
        userName,
        title,
        pageIndex,
        pageSize
      ).then(response => {
        // getpubCheckList(this.state,this.type,'','',this.pageIndex,this.pageSize).then((response)=> {
        console.log(response);
        if (response.code == 200) {
          var data = response.data.list; //当前返回的数据
          //遍历数据取详情
          for (let i = 0; i < data.length; i++) {
            if (data[i].id == this.id) {
              //找到了
              this.listData = data[i];
            }
          }
        } else {
          this.$notify.error({
            title: "异常",
            offset: 100,
            message: response.msg
          });
        }
      });
    },
    urlAdd() {
      this.$router.push({ path: "/substation/add" });
    },
    //查看详情
    handleLook(index, row) {
      if (row.id && row.id > 0) {
        //跳转到详情页
        this.$router.push({ path: "/Purchase/details", query: { id: row.id } });
      }
    },
    //去审核（显示审核界面）
    handleCheck(index, row) {
      // console.log("我是子组件"+index,row);
      if (row.id && row.id > 0) {
        this.id = row.id; //当前对象id
        this.getData(); //获得数据
        this.isChecked = true; //显示弹出框
      }
    },
    // 确定提交审核
    confirmCheck() {
      let _this = this;
      if (this.id > 0) {
        // console.log(_this.id)
        postCheckPublish(_this.id, _this.type, _this.state).then(response => {
          // console.log(response);
          if (response.code == 200) {
            _this.$message.success("操作成功");
            _this.isChecked = false;
            setTimeout(function() {
              // _this.isFlag = true;
              _this.$emit("run");
            }, 1500);
          } else {
            _this.$notify.error({
              title: "操作失败",
              duration: 2000,
              message: "失败原因：" + response.data.msg
            });
          }
        });
      }
    }
  }
};
</script>
<style lang="stylus" scoped>

.edit {
    color: #ff9800;
}

.del {
    color: #e51c23;
}

.download {
    color: #67C23A;
}

.img-box {
    overflow: hidden;
    padding-left: 30px;

    img {
        float: left;
        width: 150px;
        height: 150px;
        margin-right: 10px;
        margin-top: 10px;
        margin-bottom: 10px;
    }
}

.bs-callout {
    padding: 20px;
    border: 1px solid #eee;
    border-left-width: 5px;
    border-radius: 3px;
}

.bs-callout-danger {
    border-left-color: #ce4844;
}

.left {
    float: left;
    width: 150px;
    text-algin: center;
}

.right {
    float: left;
    width: 550px;
}
</style>


